<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>职业性格测试题目管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		$(document).ready(function() {
			//$("#name").focus();
			$("#inputForm").validate({
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
		});
		
	    function formAppendSubmit(){
	    	var choose = addSeparator('chooseVal','choose');
	    	var answer = addSeparator('answerVal','answer');
	    	if(!choose || !answer){
	    		return false;
	    	}
	    	var myform=$('#inputForm'); //得到form对象
	        myform.append(answer);
	        myform.append(choose);
	        myform.submit();
		}
	    
	    //将names的值加上|分隔符  返回一个input对象
	    function addSeparator(name,newName){
	    	var val = "";
	    	var names = document.getElementsByName(name);
            for(var i=0; i<names.length; i++){
                if(names[i].value==''){
                    return false;
                }
                val += names[i].value+"|";
            }
            val = val.substring(0,val.length-1);
            return $("<input type='text' name='"+newName+"' value='"+val+"'/>");
	    }
	    //]]>
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/front/mbtiTheme/">职业性格测试题目列表</a></li>
		<li class="active"><a href="${ctx}/front/mbtiTheme/form?id=${mbtiTheme.id}">职业性格测试题目<shiro:hasPermission name="front:mbtiTheme:edit">${not empty mbtiTheme.id?'修改':'添加'}</shiro:hasPermission><shiro:lacksPermission name="front:mbtiTheme:edit">查看</shiro:lacksPermission></a></li>
	</ul><br/>
	<form:form id="inputForm" modelAttribute="mbtiTheme" action="${ctx}/front/mbtiTheme/save" method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<sys:message content="${message}"/>	
		<div class="control-group">
			<label class="control-label">部分：</label>
			<div class="controls">
				<form:select path="part" class="input-xlarge ">
					<form:option value="" label=""/>
					<form:options items="${fns:getDictList('part_type')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
				</form:select>
			</div>
		</div>	
		<div class="control-group">
			<label class="control-label">序号：</label>
			<div class="controls">
				<form:input path="sequence" htmlEscape="false" maxlength="255" class="input-xlarge "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">题目：</label>
			<div class="controls">
				<form:input path="title" htmlEscape="false" maxlength="255" class="input-xlarge "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">A选项：</label>
			<div class="controls">
				<input type="text" name="chooseVal" value="${mbtiTheme.chooseA}" class="input-xlarge ">
				<select name="answerVal" style="width:108px;">
					<c:forEach items="${fns:getDictList('mbti_type')}" var="mbtiType">
						<option value="${mbtiType.value}" <c:if test="${mbtiType.value == mbtiTheme.answerA}">selected</c:if>>${mbtiType.label}
					</c:forEach>
				</select>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">B选项：</label>
			<div class="controls">
				<input type="text" name="chooseVal" value="${mbtiTheme.chooseB}" class="input-xlarge ">
				<select name="answerVal" style="width:108px;">
					<c:forEach items="${fns:getDictList('mbti_type')}" var="mbtiType">
						<option value="${mbtiType.value}" <c:if test="${mbtiType.value == mbtiTheme.answerB}">selected</c:if>>${mbtiType.label}
					</c:forEach>
				</select>
			</div>
		</div>
		<div class="form-actions">
			<shiro:hasPermission name="front:mbtiTheme:edit"><input id="btnSubmit" class="btn btn-primary" type="button" onclick="formAppendSubmit()" value="保 存"/>&nbsp;</shiro:hasPermission>
			<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
		</div>
	</form:form>
</body>
</html>